package com.dkd.http.controller;

import com.dkd.entity.VmTypeEntity;
import com.dkd.entity.dto.VmPageDto;
import com.dkd.entity.vo.VmTypePageVO;
import com.dkd.entity.vo.VmTypeVo;
import com.dkd.service.impl.VmTypeServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

/**
 * 售货机类型
 */
@RestController
@Slf4j
@RequestMapping("/vmType")
@RequiredArgsConstructor
@Api(tags = "售货机类型业务")
public class VmTypeController {
    private final VmTypeServiceImpl vmTypeService;

    @GetMapping("/search")
    @ApiOperation("查询售卖机类型")
    public VmTypePageVO getPage(VmPageDto vmPageDto) {
        log.info("查询售卖机类型");
        return vmTypeService.getpage(vmPageDto);
    }

    @GetMapping("/{typeId}")
    @ApiOperation("售货机类型详情")
    public VmTypeVo getTypeById(@PathVariable("typeId") Integer typeId) {
        return vmTypeService.getTypeById(typeId);
    }

    @PutMapping("/{typeId}")
    @ApiOperation("售货机类型修改")
    public boolean updateType(@RequestBody VmTypeVo VmTypeVo ) {
        VmTypeEntity vmTypeEntity = new VmTypeEntity();
        BeanUtils.copyProperties(VmTypeVo,vmTypeEntity);
        return vmTypeService.updateById(vmTypeEntity);
    }

    @DeleteMapping("/{typeId}")
    @ApiOperation("售货机删除")
    public boolean deleteVm(@PathVariable Integer typeId){
        return vmTypeService.removeById(typeId);

    }
    @PostMapping
    @ApiOperation("新增售货机类型")
    public boolean addVmType(@RequestBody VmTypeEntity vmTypeEntity){
        return vmTypeService.addVmType(vmTypeEntity);
    }

}
